#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#include<sys/types.h>
#include <linux/types.h>
#include<sys/stat.h>
#include<signal.h>

//异步IO
int fd =-1;
void handler(int signum){

    char buf[64] = {0};
    int ret = read(fd,buf,64);
    if(ret < 0){
        perror("read err");
        return;
    }else{
        printf("len = %d\n",ret);
        // printf("8888");
    }

}

int main(void){


    fd=open("/dev/input/mouse0",O_RDONLY);
    if(fd < 0){
        perror("open err:");
        return -1;
    }
    int flag = 0;
    //开房异步IO ,设置当前设备能接收到SIGIO信号
    fcntl(fd,F_SETOWN,getpid());
    flag = fcntl(fd,F_GETFL);
    flag|=FASYNC;
    fcntl(fd,F_SETFL,flag);
    signal(SIGIO,handler);
   
    while(1){
        sleep(1);
    }


    return 0;
}